package com.example.steveaoblogdemo.controller;


import com.example.steveaoblogdemo.service.impl.QiNiuUploadImpl;
import com.example.steveaoblogdemo.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
public class QiNiuController {

    @Value("${qiniu.fileDomain}")
    private String domain;
    @Resource
    private QiNiuUploadImpl qiNiuUpload;

    @PostMapping("/qiNiu/uploadImage")
    public Result<?> upload(@RequestParam("file")MultipartFile file){
        if (!file.isEmpty()){
            String filepath=qiNiuUpload.uploadPicture(file);
            String fileUrl = domain + "/" + filepath;
            return new Result<>(200,"上传成功",fileUrl);
        }
        return new Result<>(400,"上传失败",null);
    }
}
